package CSV;

import CSV.CSVLexer;
import CSV.CSVParser;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.List;
import java.util.Map;

public class CSVMain {
    public static void main(String[] args) throws Exception{
        BufferedReader reader = new BufferedReader(new FileReader("D:\\2024.8-2025.1\\compile\\demo\\src\\main\\java\\CSV\\data.csv"));

        ANTLRInputStream inputStream = new ANTLRInputStream(reader);
        CSVLexer lexer = new CSVLexer(inputStream);
        CommonTokenStream tokenStream = new CommonTokenStream(lexer);
        CSVParser parser = new CSVParser(tokenStream);
        ParseTree parseTree = parser.file();
        System.out.println(parseTree.toStringTree(parser));

        LoadCSV loader = new LoadCSV();
        ParseTreeWalker walker = new ParseTreeWalker();
        walker.walk(loader,parseTree);

        List<Map<String, String>> rows = loader.getRows();
        System.out.println(rows);
    }
}
